package com.PrintDemo;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class KillTask {
	public static void main(String[] args) throws IOException {

		try {  
			 List<String> pidList =  getPID();  
			 for(String v:pidList){
				 System.out.println(v);
				 Runtime.getRuntime().exec("taskkill /F /PID "+v);  
			 }
		   // Runtime.getRuntime().exec("taskkill /F /PID "+RBD_ECLIPSE_PID);  
		} catch (Exception e1) {  
		    e1.printStackTrace();  
		}   
	}
	
	public static List<String> getPID() {  
        List<String> pidList = new ArrayList<String>();
        String cmd = "tasklist /nh";  
        try {  
            Runtime runtime = Runtime.getRuntime();  
            Process process = runtime.exec(cmd);  
            BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));  
            String line = null;  
            while((line=br.readLine()) != null){  
                if(line.indexOf("iexplore") != -1){ 
                	line= line.replaceAll("\\s+", "#");
                	String []idkill= line.split("#");
                	if(idkill!=null&&idkill.length>=2){
                		  pidList.add(idkill[1]);
                	}
                }  
            }  
        } catch (IOException e) {  
            e.printStackTrace();  
        }  
        return pidList;  
    } 
}
